from django.db import models
from utils.base import BaseModel
from apps.interfaces.models import Api
from selenium.webdriver.common.by import By
from selenium import webdriver


class Element(BaseModel):

    class ByChoice(models.TextChoices):
        ID = By.ID, 'id'
        XPATH = By.XPATH, "xpath"
        LINK_TEXT = By.LINK_TEXT, "link text"
        PARTIAL_LINK_TEXT = By.PARTIAL_LINK_TEXT, "partial link text"
        NAME = By.NAME, "name"
        TAG_NAME = By.TAG_NAME, "tag name"
        CLASS_NAME = By.CLASS_NAME, "class name"
        CSS_SELECTOR = By.CSS_SELECTOR, "css selector"

    project = models.ForeignKey('projects.Project', on_delete=models.CASCADE)
    page = models.ForeignKey('envs.Page', on_delete=models.PROTECT)
    name = models.CharField(verbose_name='元素名称', max_length=20, unique=True, error_messages={'unique': '元素名称已存在'})
    by = models.CharField(verbose_name='元素定位方式', choices=ByChoice.choices, default=ByChoice.XPATH, max_length=20)
    value = models.CharField(verbose_name='元素定位值', max_length=200)

    class Meta:
        db_table = 'tb_element'
        verbose_name = '元素表'
        verbose_name_plural = verbose_name
